package top.glkj.hms.controller.order;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.glkj.hms.entity.OrderForm;
import top.glkj.hms.service.OrderService;
import top.glkj.hms.utils.Result;
import top.glkj.hms.utils.ResultFactory;
import top.glkj.hms.utils.Status;

/**
 * @author : xgl
 * @version : 0.0.1
 * @date :2021/3/16 11:48
 */
@Api(tags = "订单管理")
@RestController
@RequestMapping("/system/order")
public class OrderManageController {
    private final OrderService orderService;

    @Autowired
    public OrderManageController(OrderService orderService) {
        this.orderService = orderService;
    }

    @ApiOperation("获取所有订单")
    @GetMapping
    public Result getAllOrder() {
        return orderService.getAll();
    }

    @ApiOperation("根据状态获取订单")
    @GetMapping("/all")
    public Result getAllOrder(Status status) {
        return orderService.getAllOrderFormByStatus(status);
    }

    @ApiOperation("根据状态获取订单")
    @GetMapping("/{status}/{size}/{page}")
    public Result getAllOrder(@PathVariable(name = "status") String status, @PathVariable(name = "page") int page, @PathVariable(name = "size") int size) {
        return orderService.getAllOrderFormByPageAndSizeAndStatus(page, size, Status.valueOf(status));
    }

    @ApiOperation("获取待完成订单")
    @GetMapping("/{size}/{page}")
    public Result getAllOrder(@PathVariable(name = "page") int page, @PathVariable(name = "size") int size) {
        return orderService.getAllOrderFormByPageAndSizeIsNotFinnish(page, size);
    }

    /**
     * 根据状态获取订单总和
     *
     * @param status 状态
     * @return 结果
     */
    @GetMapping("/count")
    @ApiOperation("根据状态获取订单总和")
    public Result getOrderCountByStatus(Status status) {
        return ResultFactory.isDefine();
    }


    @ApiOperation("根据订单号获取订单")
    @GetMapping("/{number}")
    public Result getOrderByOrderNumber(@PathVariable String number) {
        return orderService.getOrderByOrderNumber(number);
    }

    @ApiOperation("添加订单")
    @PostMapping
    public Result addOrder(OrderForm orderForm){return orderService.addOrderForm(orderForm);}

    @ApiOperation("修改订单")
    @PutMapping
    public Result updateOrder(OrderForm orderForm){return orderService.updateOrderForm(orderForm);}
    @DeleteMapping
    @ApiOperation("移除订单")
    public Result removeOrder(OrderForm orderForm){return orderService.remove(orderForm);}

    @DeleteMapping("/delete")
    @ApiOperation("移除订单")
    public Result deleteOrder(OrderForm orderForm){return orderService.delete(orderForm);}
}
